﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Neotic.DataAccess.Sql
{
    public class Column : ISelectColumn
    {
        protected Column() { } 
        
        internal Column(IRowCollection owner, string name)
        {
            this.Owner = owner;
            this.Name = name;
        }
        
        public IRowCollection Owner { get; protected set; }
        public string Name { get; protected set; }
        public object Tag { get; set; }
        protected string _aliasName;

        public string FullName 
        {
            get { return string.Concat(Owner.AliasName, ".[", this.Name, "]"); } 
        }

        public string AliasName
        {
            get { return string.IsNullOrWhiteSpace(_aliasName) ? this.FullName : _aliasName; }
        }

        public string FullAliasName
        {
            get 
            {
                return (string.IsNullOrWhiteSpace(_aliasName)?this.FullName: string.Concat(this.FullName, " as '", _aliasName, "'")); 
            }
        }


        public OrderClauseColumn Ascending { get { return new OrderClauseColumn(this, true); } }
        public OrderClauseColumn Descending { get { return new OrderClauseColumn(this, false); } }

        public ISelectColumn As(string aliasName)
        {
            _aliasName = aliasName;
            return this;
        }

        #region Operateurs pour expression


        public static bool operator ==(Column a, object b)
        {
            return true;
        }

        public static bool operator !=(Column a, object b)
        {
            return true;
        }

        public static bool operator < (Column a, object b)
        {
            return true;
        }

        public static bool operator > (Column a, object b)
        {
            return true;
        }

        public static bool operator >=(Column a, object b)
        {
            return true;
        }

        public static bool operator <=(Column a, object b)
        {
            return true;
        }

        public static Column operator +(Column c1, object c2) 
        {
            return c1;
        }

        public static Column operator -(Column c1, object c2) 
        {
            return c1;
        }

        public static Column operator /(Column c1, object c2) 
        {
            return c1;
        }

        public static Column operator *(Column c1, object c2) 
        {
            return c1;
        }

        public static Column operator %(Column c1, object c2) 
        {
            return c1;
        }
        #endregion

    }
}
